package com.redpack.redpost.struts.action.admin;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.redpack.redpost.struts.form.admin.generalForm;
import com.redpack.redpost.util.dao.adminDAO;

public class sobreRedpost extends Action {
	
	public ActionForward execute(
			ActionMapping mapping, 
			ActionForm form, 
			HttpServletRequest request, 
			HttpServletResponse response) throws Exception {
		
		generalForm f = ( generalForm ) form ; 
		
		if( f.getBandera( ) != 1 ){
			
			
			
			return mapping.findForward( "formulario" ) ;
			
		}
			
		
		String pt = getServlet().getServletContext().getRealPath("/WebContent/imgAdmin") ;
		
		int ini = pt.indexOf(".\\")  ;
		
		String tm = pt.substring(0, ini) ;
		
		tm =  tm + "deploy\\redpost.war\\WebContent\\imgAdmin" ;
		
		byte[ ] fileData = new byte[ 0 ] ;
		
		if( f.getImagen( ) != null )
			fileData = f.getImagen( ).getFileData( ) ;
		
		boolean res = adminDAO.editTeaser( f.getCve( ), f.getNum( ), f.getTexto( ), fileData , tm , f.getNombreImg( ) ) ;
		
		return mapping.findForward("success") ;
	}

}
